//
//  HMUserTableViewCell.swift
//  WeiBo
//
//  Created by 李立达 on 15/12/10.
//  Copyright © 2015年 heima11. All rights reserved.
//

import UIKit
import SnapKit
class HMUserTableViewCell: UITableViewCell {


    var statusViewModel : HMstatusModel?{
    
        didSet{
            orginalview.statusModel = statusViewModel
            toolBarView.toolBarModel = statusViewModel
            
            toolBarTopConstraint?.uninstall()
            
            if statusViewModel?.hmstatus?.retweeted_status != nil
            {
                retweetView.hidden = false
                
                retweetView.retweetModel = statusViewModel
                
                toolBarView.snp_updateConstraints(closure: { (make) -> Void in
                    
                    self.toolBarTopConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
                })
            }
            else
            {
                retweetView.hidden = true
                
                toolBarView.snp_updateConstraints(closure: { (make) -> Void in
                    
                    self.toolBarTopConstraint = make.top.equalTo(orginalview.snp_bottom).constraint
                })
            }
            
        }
    }
    
    var toolBarTopConstraint : Constraint?
    
    lazy var orginalview : HMOriginalView = HMOriginalView()
    lazy var retweetView : HMRetweetView = HMRetweetView()
    lazy var toolBarView : HMToolBarView = HMToolBarView()
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        stetupUI()
    
    }

    required init?(coder aDecoder: NSCoder) {
        
        fatalError("")
    }
    
    
    func stetupUI(){
    
        contentView.addSubview(orginalview)
        contentView.addSubview(retweetView)
        contentView.addSubview(toolBarView)
        
        orginalview.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
            make.top.equalTo(contentView)
        }
        retweetView.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(contentView)
            make.trailing.equalTo(contentView)
            make.top.equalTo(orginalview.snp_bottom)
        }
        
        toolBarView.snp_makeConstraints { (make) -> Void in
            
            self.toolBarTopConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
            make.leading.equalTo(contentView)
            make.width.equalTo(contentView)
            make.height.equalTo(35)
        }
        
        contentView.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(self)
            make.trailing.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(toolBarView.snp_bottom)
        }
    }
    
    
}
